const express = require('express');
const router = express.Router();
const Database = require('../model/connectDatabase');
const database = new Database().mysql
const {SuccessModel,ErrorModel} = require('../model/resData')

router.post('/',(req,res,next)=>{
    let {username,password} = req.body
    let keys= [username,password]
    let sql = 'select id,username from users where(username=? and password=?)'
    database.query(sql,keys,(err,data)=>{
       if(err){
            res.send(new ErrorModel(data,'数据库访问错误'))
       }else if(data != ''){
           res.send(new SuccessModel(data,'登录成功'))
       }else{
        res.send(new ErrorModel(data,'登录失败'))
       }
    })
})

module.exports = router;